package com.cq.hd.app.controller;

import com.cq.hd.app.biz.SubsidyBiz;
import com.cq.hd.common.annotation.LoginUser;
import com.cq.hd.common.entity.AppLoginUser;
import com.cq.hd.common.entity.BusinessInfo;
import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.member.api.dto.SubsidyAmtBillDto;
import com.cq.hd.member.api.vo.BusinessSubsidyVo;
import com.cq.hd.member.api.vo.SubsidyAmtBillVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@RestController
@RequestMapping("/subsidy")
@Api(tags = "商家补贴金相关接口")
public class SubsidyController extends BaseController {

    @Autowired
    private SubsidyBiz subsidyBiz;

    @ApiOperation(value = "补贴账户页面数据")
    @ApiResponse(response = BusinessSubsidyVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/getSubsidyData")
    public Result<BusinessSubsidyVo> getSubsidyData(@ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        Long businessId = 0L;
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            businessId = businessInfo.getId();
        }

        return ResultGenerator.success(subsidyBiz.getSubsidyData(businessId, appLoginUser.getUserId()));
    }

    @ApiOperation(value = "补贴金资金明细")
    @GetMapping("/list")
    public Result<List<SubsidyAmtBillVo>> list(@ApiIgnore @LoginUser AppLoginUser appLoginUser, SubsidyAmtBillDto subsidyAmtBillDto) {
        Long businessId = 0L;
        BusinessInfo businessInfo = appLoginUser.getUserInfo().getBusinessInfo();
        if (businessInfo != null) {
            businessId = businessInfo.getId();
        }

        subsidyAmtBillDto.setBusinessId(businessId);
        subsidyAmtBillDto.setUserId(appLoginUser.getUserId());
        return subsidyBiz.listSubsidyAmtBill(subsidyAmtBillDto);
    }

}
